import { useMemo, useState } from "react"

// 递归计算斐波那契数列之和
function fib(n){
    console.log('执行fib函数')
    if(n<3)
        return 1
    return fib(n-1)+fib(n-2)
}

const UseMemo=()=>{
    const [count1,setCount1]=useState(0)
    // const result=fib(count1)
    const result=useMemo(()=>{
        return fib(count1)
    },[count1])
    const [count2,setCount2]=useState(0)
    console.log('组件重新渲染')
    return(
        <div>
            <button onClick={()=>setCount1(count1+1)}>add count1:{count1}</button>
            <button onClick={()=>setCount2(count2+1)}>add count2:{count1}</button>
            result={result}
        </div>
    )
}

export default UseMemo